#include "fileparser.h"
#include "altadjacencestructgraph.h"
#include "graphprinter.h"
#include "algorithms.h"

#include <fstream>
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
  ifstream file(argv[1]);

  Parser parser(file);
  
  parser.parse();

  vector<Parser::Pair> edges = parser.getEdges();

  int nNodes = parser.getNumberOfNodes();

  AltAdjacenceStructGraph<int,int> graph;

  for (int i = 0; i < nNodes; i++) {
    graph.addNode(i + 1);
  }

  for (Parser::Pair edge: edges) {
    graph.addEdge(edge.node1, edge.node2, edge.node1 + edge.node2);
  }

  printGraph<AltAdjacenceStructGraph<int,int>>(cout,graph);

  {
    for (int i: bfs<AltAdjacenceStructGraph<int,int>>(graph,0)) {
      cerr << i + 1 << ", ";
    }
    cerr << endl;
  }

  // imprime a árvore da busca em profundidade
  {
    auto d = ArticulationSearch<AltAdjacenceStructGraph<int,int>>(graph).dfs(0);

    AltAdjacenceStructGraph<int,int> tree;

    for (int i = 0; i < graph.countNodes(); i++) {
      tree.addNode(i+1);
    }

    for (int i = 0; i < d.incideOut.size(); i++) {
      for (auto a: d.incideOut[i]) {
        tree.addEdge(i,a);
      }
    }
    
    ofstream file("tree.dot");

    printGraph<AltAdjacenceStructGraph<int,int>>(file,tree);
  }

  {
    vector<int> articulations = ArticulationSearch<AltAdjacenceStructGraph<int,int>>(graph).getArticulations(0);
    for (int i: articulations) {
      cerr << i + 1 << " é uma articulação" << endl;
    }
  }
}

